﻿// TestSortCoords.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;

struct Point
{
    int x;
    int y;
};

vector<Point> org;
vector<Point> res;

void init_struct()
{
    for (int i = 0; i < 10; i++)
    {
        Point pt;
        pt.x = i;
        pt.y = i * rand() % 100;
        org.push_back(pt);
    }
}

void sort_y(vector<Point> point, int n)
{
    int i, j, k;
    double t, u;
    for (i = 0; i < n - 1; ++i)
    {
        k = i;
        for (j = i + 1; j < n; ++j)
        {
            if (point[k].y < point[j].y)
                k = j;
        }
        if (k != i)
        {
            t = point[k].x;
            point[k].x = point[i].x;
            point[i].x = t;

            u = point[k].y;
            point[k].y = point[i].y;
            point[i].y = u;
        }
    }
    //将排序后的坐标点存放到一个新容器当中
    for (int i = 0; i < 10; i++)
        res.push_back(point.at(i));
}

int main()
{
    init_struct();
    sort_y(org, 10);
    for (int i = 0; i < 10; i++)
    {
        cout << res.at(i).x << "," << res.at(i).y << endl;
    }
}
